﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Epsilon.Expr;

namespace Epsilon
{
    public interface IPattern { }

    public class PatternTuple : Expression, IPattern
    {
        public List<IPattern> Patterns { get; private set; }

        public PatternTuple(List<IPattern> ps, int l, int c)
            : base(l, c)
        {
            Patterns = ps;
        }

        public override string ToString()
        {
            string s = "{";

            for (int i = 0; i < Patterns.Count; i++)
            {
                if (i > 0)
                    s += ", ";
                s += Patterns[i].ToString();
            }

            return s + "}";
        }
    }

    public class PatternRec : Expression, IPattern
    {
        public string Name { get; private set; }
        public List<PatternRecField> Fields { get; private set; }

        public PatternRec(string name, List<PatternRecField> fields, int l, int c)
            : base(l, c)
        {
            Name = name;
            Fields = fields;
        }

        public override string ToString()
        {
            string s = "#" + Name + "{";

            for (int i = 0; i < Fields.Count; i++)
            {
                if (i > 0)
                    s += ", ";
                s += Fields[i].ToString();
            }

            return s + "}";
        }
    }

    public class PatternRecField : Expression
    {
        public string Name { get; private set; }
        public IPattern Pattern { get; private set; }

        public PatternRecField(string name, IPattern pattern, int l, int c)
            : base(l, c)
        {
            Name = name;
            Pattern = pattern;
        }

        public override string ToString()
        {
            return Name + " = " + Pattern.ToString();
        }
    }
}
